<extend name="Public/base"/>

<block name="body">
	<div class="main-title">
		<h2>{:I('id')?'编辑':'新增'}</h2>
	</div>
	{:$allhtml}
</block>

<block name="script">

	<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
	<script type="text/javascript">
		var that = this;
		//导航高亮
		highlight_subnav('{:U('Config/index')}');

		function upload_picture(name){
			//上传图片
		    /* 初始化上传插件 */
			$("#upload_picture_"+name).uploadify({
		        "height"          : 30,
		        "swf"             : "__STATIC__/uploadify/uploadify.swf",
		        "fileObjName"     : "download",
		        "buttonText"      : "上传图片",
		        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
		        "width"           : 120,
		        'removeTimeout'	  : 1,
		        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
		        "onUploadSuccess" : uploadPicture,
		        'onFallback' : function() {
		            alert('未检测到兼容版本的Flash.');
		        }
		    });

			function uploadPicture(file, data){
		    	var data = $.parseJSON(data);
		    	var src = '';
		        if(data.status){
		        	$("#cover_id_"+name).val(data.path);
		        	src = data.url || '__ROOT__' + data.path

		        	$("#cover_id_"+name).parent().find(".upload-img-box").html(
		        		'<div class="upload-pre-item"><img src="' + src + '"/></div>'
		        	);
		        } else {
		        	updateAlert(data.info);
		        	setTimeout(function(){
		                $('#top-alert').find('button').click();
		                $(that).removeClass('disabled').prop('disabled',false);
		            },1500);
		        }
		    }
	    }


	    function upload_file(name){
			//上传文件
		    /* 初始化上传插件 */
			$("#upload_file_"+name).uploadify({
		        "height"          : 30,
		        "swf"             : "__STATIC__/uploadify/uploadify.swf",
		        "fileObjName"     : "download",
		        "buttonText"      : "上传附件",
		        "uploader"        : "{:U('File/uploadFiles',array('session_id'=>session_id()))}",
		        "width"           : 120,
		        'removeTimeout'	  : 1,
		        "onUploadSuccess" : uploadFile,
		        'onFallback' : function() {
		            alert('未检测到兼容版本的Flash.');
		        }
		    });

			function uploadFile(file, data){
				var data = $.parseJSON(data);
		        if(data.status){
		        	$("input[name="+name+"]").val(data.data);
		        	$("input[name="+name+"]").parent().find('.upload-img-box').html(
		        		"<div class=\"upload-pre-file\"><span class=\"upload_icon_all\"></span>" + data.info + "</div>"
		        	);
		        } else {
		        	updateAlert(data.info);
		        	setTimeout(function(){
		                $('#top-alert').find('button').click();
		                $(that).removeClass('disabled').prop('disabled',false);
		            },1500);
		        }
		    }
	    }

		function upload_more_picture(name){
			//上传图片
		    /* 初始化上传插件 */
			$("#upload_picture_"+name).uploadify({
		        "height"          : 30,
		        "swf"             : "__STATIC__/uploadify/uploadify.swf",
		        "fileObjName"     : "download",
		        "buttonText"      : "上传图片",
		        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
		        "width"           : 120,
				"multi"			  : true,
		        'removeTimeout'	  : 1,
		        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
		        "onUploadSuccess" : upload_more_Picture,
		        'onFallback' : function() {
		            alert('未检测到兼容版本的Flash.');
		        }
		    });

			function upload_more_Picture(file, data){
		    	var data = $.parseJSON(data);
		    	var src = '';
		        if(data.status){
		        	$("#cover_id_"+name).val($("#cover_id_"+name).val()+","+data.path);
		        	src = data.url || '__ROOT__' + data.path

		        	$("#cover_id_"+name).parent().find(".upload-img-box").prepend(
		        		'<div class="upload-pre-item"><img src="' + src + '"/></div>'
		        	);
		        } else {
		        	updateAlert(data.info);
		        	setTimeout(function(){
		                $('#top-alert').find('button').click();
		                $(that).removeClass('disabled').prop('disabled',false);
		            },1500);
		        }
		    }
	    }

		//清除多图片上传
		function clear_more_Picture(name){
			$("#cover_id_"+name).val('');
			$("#cover_id_"+name).parent().find(".upload-img-box").html('');
		}
	</script>
</block>
